package com.ruoyi.app.controller;


import com.ruoyi.app.domain.CaseCopyApply;
import com.ruoyi.app.service.CaseCopyApplyService;
import com.ruoyi.app.util.Result;
import com.ruoyi.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("caseCopyApply")
public class CaseCopyApplyController {
    @Autowired
    private CaseCopyApplyService caseCopyApplyService;

    @Autowired
    RedisService redisService;

    // 步骤暂存
    @RequestMapping("cacheStep")
    public Result cacheStep(@RequestBody CaseCopyApply caseCopyApply, String applyId) {
//        System.err.println("传回来的是" + caseCopyApply + "===后边的ID是 : " + applyId);
        redisService.setCacheObject("caseCopyApply:" + applyId, caseCopyApply);
        CaseCopyApply caseCopyAppl = redisService.getCacheObject("caseCopyApply:" + applyId);
        System.out.println(caseCopyAppl + " : + :  applyId :  " + applyId);
        return Result.ok("暂存成功");
    }

    // 最终提交
    @RequestMapping("add")
    public Result finalSubmit( String applyId) {
        System.err.println("阿达大是啊 : "+applyId);
        CaseCopyApply caseCopyApply = redisService.getCacheObject("caseCopyApply:" + applyId);
        if (caseCopyApply != null) {
            System.err.println("要添加的数据");
            caseCopyApplyService.add(caseCopyApply);
            redisService.deleteObject("caseCopyApply:" + applyId);
            return Result.ok("添加成功");
        }
        return Result.error("未找到缓存数据");
    }
}
